package com.jc.subject.domin.handler.subject;

import com.jc.subject.common.enums.IsDeletedFlagEnum;
import com.jc.subject.common.enums.SubjectInfoTypeEnum;
import com.jc.subject.domin.convert.SubjectJudgeConverter;
import com.jc.subject.domin.convert.SubjectRadioConverter;
import com.jc.subject.domin.entity.SubjectAnswerBO;
import com.jc.subject.domin.entity.SubjectInfoBO;
import com.jc.subject.domin.entity.SubjectOptionBO;
import com.jc.subject.infra.basic.entity.SubjectBrief;
import com.jc.subject.infra.basic.entity.SubjectJudge;
import com.jc.subject.infra.basic.entity.SubjectRadio;
import com.jc.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @Description: 判断题目的策略类
 * @Author: ASL_ly
 * @Package: com.jc.subject.domin.handler.subject
 * @Project: jc-club
 * @Date: 2024/10/23  20:38
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectJudgeService subjectJudgeService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {

        SubjectJudge subjectJudge = new SubjectJudge();
        SubjectAnswerBO subjectAnswerBO = subjectInfoBO.getOptionList().get(0);
        subjectJudge.setSubjectId(subjectInfoBO.getId());
        subjectJudge.setIsCorrect(subjectAnswerBO.getIsCorrect());
        subjectJudge.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.code);
        subjectJudgeService.insert(subjectJudge);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        SubjectJudge subjectJudge= SubjectJudge.builder()
                .subjectId(subjectId)
                .isDeleted(IsDeletedFlagEnum.UN_DELETED.code)
                .build();
        List<SubjectJudge> subjectJudgeList = subjectJudgeService.queryByCondition(subjectJudge);
        List<SubjectAnswerBO> subjectAnswerBOList = SubjectJudgeConverter
                .INSTANCE.subjectJudgeToAnswerBOList(subjectJudgeList);
        SubjectOptionBO subjectOptionBO =new SubjectOptionBO();
        subjectOptionBO.setOptionList(subjectAnswerBOList);
        return subjectOptionBO;
    }
}
